﻿#include<stdio.h>


#include"LTC2943.h"

void test1()
{
	uint8_t Accumulated_Charge_data_1[2] = { 0X81, 0X06 };
	//uint8_t Accumulated_Charge_data_2[2] = { 0X2D, 0X2F };
	//uint8_t Accumulated_Charge_data_3[2] = { 0X2D, 0XAC };
	printf("累计电荷1：%f mAh\n", LTC2943_Accumulated_Charge_calculation(Accumulated_Charge_data_1));
	//printf("电压2：%f V\n", LTC2943_Accumulated_Charge_calculation(Accumulated_Charge_data_2));
	//printf("电压3：%f V\n", LTC2943_Accumulated_Charge_calculation(Accumulated_Charge_data_3));
	puts("\n\n");
}

void test2()
{
	uint8_t Voltage_data_1[2] = { 0XB0, 0X1C };
	uint8_t Voltage_data_2[2] = { 0X2D, 0X2F };
	uint8_t Voltage_data_3[2] = { 0X2D, 0XAC };
	printf("电压1：%f V\n", LTC2943_Voltage_calculation(Voltage_data_1));
	printf("电压2：%f V\n", LTC2943_Voltage_calculation(Voltage_data_2));
	printf("电压3：%f V\n", LTC2943_Voltage_calculation(Voltage_data_3));
	puts("\n\n");
}

void test3()
{
	uint8_t Current_data_1[2] = { 0XA8, 0X40 };
	uint8_t Current_data_2[2] = { 0X7F, 0XF0 };
	uint8_t Current_data_3[2] = { 0X7F, 0XE0 };
	printf("电流1：%f A\n", LTC2943_Current_calculation(Current_data_1));
	printf("电流2：%f A\n", LTC2943_Current_calculation(Current_data_2));
	printf("电流3：%f A\n", LTC2943_Current_calculation(Current_data_3));
	puts("\n\n");
}

void test4()
{
	uint8_t Temperature_data_1[2] = { 0X96, 0X96 };
	uint8_t Temperature_data_2[2] = { 0X97, 0X40 };
	uint8_t Temperature_data_3[2] = { 0X96, 0X60 };
	printf("温度1：%f ℃\n", LTC2943_Temperature_calculation(Temperature_data_1));
	printf("温度2：%f ℃\n", LTC2943_Temperature_calculation(Temperature_data_2));
	printf("温度3：%f ℃\n", LTC2943_Temperature_calculation(Temperature_data_3));
	puts("\n\n");
}

int main()
{
	/*test1();
	test2();
	test3();
	test4();*/

	//uint16_t a = 0x03;
	//printf("a = %#2X\n", a);
	//uint16_t b = 0x05;
	//printf("b = %#2X\n", b);

	//printf("a-b = %d(DEC) = %#X(HEX)\n", a - b, a - b);

	//int32_t c_int = a - b;
	//printf("c_int = a - b = %d\n", c_int);
	//printf("c_int = %#X\n", c_int);
	//memPrint((uint8_t*)&c_int, 4);
	//
	//uint16_t c_uint = a - b;
	//printf("c_uint = a - b = %d\n", c_uint);
	//printf("c_uint = %#X\n", c_uint);
	//memPrint((uint8_t*)&c_uint, 2);


	//const int a = 7;
	////a = 8;//错误
	


	uint8_t  Control_Register_record[] = { 0X00, 0X08, 0X10, 0X18, 0X20, 0X28, 0X30,0X38,0X3C };//用来记录控制寄存器的设置
	for (int i = 0; i < 9; i++)
	{
		uint8_t tem = (Control_Register_record[i] & 0X3C) >> 3;
		if (tem > 0X06) tem = 0X06;
		uint16_t Prescaler_record = 0X0001 << (2 * tem);//记录预分配系数
		printf("Prescaler_record = %d \n", Prescaler_record);
	}
	




	return 0;
}
